home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / vis082s.arc / USERRET.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-17  |  5KB  |  227 lines

  1.  
  2. {$R-,S-,I-,D-,F+,V-,B-,N-,L+ }
  3.  
  4. unit userret;
  5.  
  6. interface
  7.  
  8. uses dos,
  9.      gentypes,gensubs,subs1,configrt,mailret,textret;
  10.  
  11. procedure writeufile (var u:userrec; n:integer);
  12. procedure writeurec;
  13. procedure readurec;
  14. function validuname (m:mstr):boolean;
  15. function lookupuname (n:integer):mstr;
  16. function lookupuser (var uname:mstr):integer;
  17. function adduser (var u:userrec):integer;
  18. procedure updateuserstats (disconnecting:boolean);
  19.  
  20. implementation
  21.  
  22. procedure writeufile (var u:userrec; n:integer);
  23. begin
  24.   seek (ufile,n);
  25.   write (ufile,u);
  26.   seek (uhfile,n);
  27.   write (uhfile,u.handle)
  28. end;
  29.  
  30. procedure writeurec;
  31. begin
  32.   if unum<1 then exit;
  33.   urec.level:=ulvl;
  34.   urec.handle:=unam;
  35.   writeufile (urec,unum)
  36. end;
  37.  
  38. procedure readurec;
  39. begin
  40.   seek (ufile,unum);
  41.   read (ufile,urec);
  42.   ulvl:=urec.level;
  43.   unam:=urec.handle
  44. end;
  45.  
  46. function validuname (m:mstr):boolean;
  47. var n:integer;
  48. begin
  49.   if length(m)>0
  50.     then if (m<>'?') and (m[1]<>'#') and (m[1]<>'/') and (m[length(m)]<>'*')
  51.                      and (not match(m,'new')) and (not match(m,'q'))
  52.       then if valu(m)=0
  53.         then validuname:=true
  54.         else begin
  55.           validuname:=false;
  56.           writeln (^B'Invalid user name!')
  57.         end
  58. end;
  59.  
  60. function lookupuname (n:integer):mstr;
  61. var un:mstr;
  62. begin
  63.   if (n<1) or (n>numusers) then un:='* Unknown *' else begin
  64.     seek (uhfile,n);
  65.     read (uhfile,un);
  66.     if length(un)=0 then un:='* User Disappeared *'
  67.   end;
  68.   lookupuname:=un
  69. end;
  70.  
  71. function lookupuser (var uname:mstr):integer;
  72. var cnt,s:integer;
  73.     wildcarding:boolean;
  74.     k:char;
  75.     uh:mstr;
  76. begin
  77.   lookupuser:=0;
  78.   if length(uname)=0 then exit;
  79.   if uname[1]='/' then exit;
  80.   if uname[1]='#' then delete (uname,1,1);
  81.   wildcarding:=uname[length(uname)]='*';
  82.   if wildcarding then uname[0]:=pred(uname[0]);
  83.   val (uname,cnt,s);
  84.   if (s=0) and (cnt>0) and (cnt<=numusers) then begin
  85.     seek (uhfile,cnt);
  86.     read (uhfile,uh);
  87.     if length (uh)>0 then begin
  88.       lookupuser:=cnt;
  89.       uname:=uh
  90.     end;
  91.     exit
  92.   end;
  93.   seek (uhfile,1);
  94.   for cnt:=1 to numusers do
  95.     begin
  96.       read (uhfile,uh);
  97.       if wildcarding and (uh<>'')
  98.         then if match(copy(uh,1,length(uname)),uname)
  99.           then
  100.             begin
  101.               write (^R,uh,^S' [Y/N/X]: ');
  102.               repeat
  103.                 read (k);
  104.                 k:=upcase(k)
  105.               until hungupon or (k in ['Y','N','X']);
  106.               writeln (k);
  107.               case upcase(k) of
  108.                 'Y':begin
  109.                       lookupuser:=cnt;
  110.                       uname:=uh;
  111.                       exit
  112.                     end;
  113.                  'X':exit
  114.               end
  115.             end
  116.           else
  117.         else if match (uh,uname)
  118.           then
  119.             begin
  120.               lookupuser:=cnt;
  121.               uname:=uh;
  122.               exit
  123.             end
  124.     end
  125. end;
  126.  
  127. function adduser (var u:userrec):integer;
  128. var un:userrec;
  129.     num,cnt:integer;
  130.     level:integer;
  131.     handle:mstr;
  132.     password:sstr;
  133.     phonenum:sstr;
  134.     usernote:mstr;
  135. label found;
  136. begin
  137.   num:=numusers+1;
  138.   for cnt:=1 to numusers do begin
  139.     seek (ufile,cnt);
  140.     read (ufile,un);
  141.     if length(un.handle)=0 then
  142.       begin
  143.         num:=cnt;
  144.         goto found
  145.       end
  146.   end;
  147.   if num>maxusers then begin
  148.     adduser:=-1;
  149.     exit
  150.   end;
  151.   if notvalidas and (num>5) then begin
  152.     adduser:=-1;
  153.     exit
  154.   end;
  155.   numusers:=num;
  156.   found:
  157.   phonenum:=u.phonenum;
  158.   usernote:=u.usernote;
  159.   handle:=u.handle;
  160.   level:=u.level;
  161.   password:=u.password;
  162.   fillchar (u,sizeof(u),0);
  163.   u.config:=[lowercase,eightycols,linefeeds,postprompts,asciigraphics,ansigraphics];
  164.   u.statcolor:=configset.defstacolor;
  165.   u.regularcolor:=configset.defreg;
  166.   u.promptcolor:=configset.defpromp;
  167.   u.inputcolor:=configset.definput;
  168.   u.menuboard:=27;
  169.   u.menuback:=27;
  170.   u.menuhighlight:=15;
  171.   u.statusboxcolor:=1;
  172.   u.blowboard:=configset.defblowbor;
  173.   u.blowinside:=configset.defblowin;
  174.   u.udlevel:=level;
  175.   u.udpoints:=configset.defudpoint;
  176.   u.emailannounce:=-1;
  177.   u.infoform:=-1;
  178.   u.conf[1]:=true;
  179.   u.conf[2]:=False;
  180.   u.Conf[3]:=False;
  181.   u.Conf[4]:=False;
  182.   U.Conf[5]:=False;
  183.   u.infoform2:=-1;
  184.   u.infoform3:=-1;
  185.   u.infoform4:=-1;
  186.   u.infoform5:=-1;
  187.   u.displaylen:=25;
  188.   u.handle:=handle;
  189.   u.level:=level;
  190.   u.udratio:=configset.minudrati;
  191.   u.udkratio:=configset.minud;
  192.   u.pcratio:=configset.minpc;
  193.   u.phonenum:=phonenum;
  194.   u.usernote:=usernote;
  195.   u.password:=password;
  196.   writeufile (u,num);
  197.   adduser:=num
  198. end;
  199.  
  200. procedure updateuserstats (disconnecting:boolean);
  201. var timeon:integer;
  202. begin
  203.   with urec do begin
  204.     timeon:=timeontoday;
  205.     timetoday:=timetoday-timeon;
  206.     if timetoday<0 then timetoday:=0;
  207.     totaltime:=totaltime+timeon;
  208.     if tempsysop then begin
  209.       ulvl:=regularlevel;
  210.       writeln (usr,'(Disabling temporary sysop powers)');
  211.       writeurec
  212.     end;
  213.     if disconnecting and (numon=1) then begin
  214.       if (ulvl=1) and (configset.level2n<>0) then ulvl:=configset.level2n;
  215.       if (udlevel=configset.defudleve) and (configset.udlevel2n<>0) then udlevel:=configset.udlevel2n;
  216.       if (udpoints=configset.defudpoint) and (configset.udpoints2n<>0)
  217.         then udpoints:=configset.udpoints2n
  218.     end;
  219.     if not disconnecting then writedataarea
  220.   end;
  221.   writeurec
  222. end;
  223.  
  224.  
  225. begin
  226. end.
  227.